package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    UserService userService = new UserServiceImpl();
    //UserController/getUserByIdByPass
    public User getUserByIdByPass(HttpServletRequest request){
        String id = request.getParameter("userId");
        String pass = request.getParameter("password");
        User user = userService.squery(id,pass);
        return user;
    }
//UserController/getUserById
    public int getUserById(HttpServletRequest request){
        String id = request.getParameter("userId");
        int a = userService.squeryrow(id);
        return a;
    }
//UserController/saveUser
    public int saveUser(HttpServletRequest request){
        String id = request.getParameter("userId");
        String pass = request.getParameter("password");
        String name = request.getParameter("userName");
        String sex = request.getParameter("userSex");
        int s = Integer.parseInt(sex);
        User user = new User();
        user.setUserId(id);
        user.setPassword(pass);
        user.setUserName(name);
        user.setUserSex(s);
        int a = userService.suinsert(user);
        return a;
    }
}
